//
//  Evaluation.h
//  Dictionary
//
//  Created by Rune Laugesen on 23/08/11.
//  Copyright 2011 Copenhagen University. All rights reserved.
//
//
//   Evaluate on word length = predict length, word length <= predict length
//   Also get KSPC evaluation (measurement = avg number on reranked list)
//

#ifndef Dictionary_Evaluation_h
#define Dictionary_Evaluation_h

#include "Instances.h"
#include "Classifier.h"
#include "KeyMapper.h"
#include "SWPSUtil.h"
#include <iomanip>

using namespace std;

struct TrainingInstance
{
    string word;
    vector<string> features;
};

static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50)
{
    if ( (x != n) && (x % (n/100) != 0) ) return;
    
    float ratio  =  x/(float)n;
    int   c      =  ratio * w;
    
    cout << setw(3) << (int)(ratio*100) << "% [";
    for (int x=0; x<c; x++) cout << "=";
    for (int x=c; x<w; x++) cout << " ";
    cout << "]\r" << flush;
}

class Evaluation
{
private:
    vector<TrainingInstance> _testdata;
    vector<string> _classified;
    map<string, map<double, string> > _misclassified;
    
public:
    Evaluation();
    void KeyStrokPerCharacter(bool verbose = false);
    void DisambiguatedAccuracy(Classifier* classifier, KeyMapper* keymapper, SWPS swps, bool verbose = false);
    void BuildTestData(vector<vector<string> > testdata, map<string, vector<string> > featuredata, SWPS swps);
    bool caseInsensitiveStringCompare(const string& str1, const string& str2);
};

#endif
